package com.jinyang.jetpackdemo.util.http

import com.jinyang.jetpackdemo.util.http.model.BaseHttpResponse
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.http.*

/**
 * @Author: LiuJinYang
 * @CreateDate: 2020/5/16 11:00
 */
interface ApiService {
    /**
     * get
     */
    @JvmSuppressWildcards
    @GET
    suspend fun get(
        @Url url: String,
        @QueryMap options: Map<String, Any?>?
    ): BaseHttpResponse<Any?>?

    /**
     * post
     *
     *
     * # @Body:用于POST请求体，将实例对象根据转换方式转换为对应的json字符串参数， 这个转化方式是GsonConverterFactory定义的。
     */
    @JvmSuppressWildcards
    @Headers("Content-Type: application/json", "Accept: application/json")
    @POST
    suspend fun postJson(
        @Url url: String,
        @Body route: Map<String, Any?>?
    ): BaseHttpResponse<Any?>?

    /**
     * post
     *
     *
     * # @FieldMapPost方式传递简单的键值对,
     * 需要添加@FormUrlEncoded表示表单提交
     */
    @JvmSuppressWildcards
    @FormUrlEncoded
    @POST
    suspend fun postForm(
        @Url url: String,
        @FieldMap maps: Map<String, Any?>?
    ): BaseHttpResponse<Any?>?

    @JvmSuppressWildcards
    @Headers("Content-Type: application/json", "Accept: application/json")
    @POST
    suspend fun postJsonStr(
        @Url url: String?,
        @Body params: RequestBody?
    ): BaseHttpResponse<Any?>?

    @JvmSuppressWildcards
    @POST
    suspend fun uploadFile(
        @Url url: String,
        @Body body: RequestBody
    ): BaseHttpResponse<Any?>?

    /**
     * 下载文件
     */
    @JvmSuppressWildcards
    @Streaming
    @GET
    @Headers("Accept-Encoding: identity")
    suspend fun downloadFile(@Url url: String?): ResponseBody
}